import React, { Component, ComponentClass } from 'react';
import Taro from '@tarojs/taro';
import {AtIcon} from "taro-ui";
import {Image, View} from '@tarojs/components'
import {user} from "../../../utils/user.service";
import {ROOKIEGUID_GETIMG} from "../../../constants/api"
import {http} from "../../../utils/http";
import './anovice.scss'

type PageOwnProps = {};
type PageState = {
  intro_img: string
}

class Index extends Component {
  state: PageState = {
    intro_img: ''
  }

  async componentDidShow() {
    const isLogin = await user.checkLogin()
    if (!isLogin) {
      Taro.showToast({
        title: '你还未登录，请登录',
        icon: 'none',
      })
      const timer = setTimeout(() => {
        clearTimeout(timer)
        user.jumpLogin()
      }, 1500)
      return
    }
    const res = await http.HPost(ROOKIEGUID_GETIMG, {})
    if (res) {
      this.setState({
        intro_img: res.data.intro_img
      })
    }
  }
  getHistoryLength(){
    return window.history.length > 0
  }

  render() {
    const {intro_img} = this.state;
    return (
      <View className='anovice-img'>
        {process.env.TARO_ENV ==='h5' && this.getHistoryLength() && <View style='width: 36Px;height: 36Px;border-radius: 50%;background-color: rgba(0,0,0,.3);display: flex;align-items: center;justify-content: center;position: absolute;top: 15px;left: 15px;z-index: 99;' onClick={()=> Taro.navigateBack()}>
          <AtIcon value='icon icon-a-2tubiaozhizuomoban-01-011' color='#fff' customStyle='transform: rotate(90deg);vertical-align: inherit;' size='20px' />
        </View> }
        <Image src={intro_img} mode='widthFix' className='img' style='width: 100%;' />
      </View>
    );
  }
}

export default Index as ComponentClass<PageOwnProps, PageState>
